package cn.tedu.egweibo03.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;

    /**
     * 1.针对没有具体数据返回的控制器方法
     *   return new JsonResult(StatusCode.OPERATION_SUCCESS);
     */
    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    /**
     * 2.针对有具体数据返回的控制器方法
     *   return new JsonResult(StatusCode.OPERATION_SUCCESS, weiboDetailVO);
     */
    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    /**
     * 3.针对于操作成功的场景,进行方法的封装;
     *   3.1 静态方法1: 有具体的数据返回的,操作成功的场景;
     *       return JsonResult.ok(data);
     *   3.2 静态方法2: 没有具体的数据返回的,操作成功的场景;
     */
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult ok(){
        return ok(null);
    }




}
